<template>
  <div class="flexContent">
    <div class="top">
      <h3>退货信息</h3>
      <div class="rows">
        <span class="col">退货编号：{{ returnsNumber }}</span>
        <span class="col">退货总额：{{ returnMoney }}元</span>
        <span class="col">退货仓库：{{ warehouseName }}</span>
      </div>
      <div class="rows one-line">
        <span class="col">备注：{{ remark ? remark : "无" }}</span>
      </div>
    </div>
    <div class="table">
      <div class="inner">
        <el-table border class="tablebox" :max-height="475" :data="tableData" size="medium">
          <el-table-column label="序号" type="index" align="center" width="80" />
          <el-table-column align="center" label="商品名称" prop="commodityName" />
          <el-table-column align="center" label="规格" prop="commodityStandard" />
          <el-table-column align="center" label="商品条码" prop="barCode" />
          <el-table-column align="center" label="配送规格" prop="deliveryNorms" />
          <el-table-column align="center" label="已退数量" prop="returnedCount" />
          <el-table-column align="center" label="退货数量" prop="returnNum" />
          <el-table-column align="center" label="退货件数" prop="returnCount" />
          <el-table-column align="center" label="批次号" prop="batchNumber" />
          <el-table-column align="center" width="300" fixed="right" label="返仓方式" prop="type" v-if="isDetail == 'SH'">
            <template v-slot="{ row }">
              <el-radio-group v-model="row.type">
                <el-radio label="1">正常返仓</el-radio>
                <el-radio label="0">异常返仓</el-radio>
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column align="center" width="300" fixed="right" label="返仓方式" prop="type"
            v-if="isDetail == 'detail' && returnsState != '0'">
            <template v-slot="{ row }">
              <span>{{ row.type == 1 ? "正常返仓" : "异常返仓" }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="returnBtn">
      <el-button class="addBtn" type="success" @click="toExamine(2)" v-if="isDetail == 'SH'">审核通过</el-button>
      <el-button class="delBtn" type="danger" @click="toExamine(1)" v-if="isDetail == 'SH'">审核拒绝</el-button>
      <el-button class="celBtn" @click="returnList">返回</el-button>
    </div>
  </div>
</template>

<script>
import { reqToExamine, reqExamineById } from "@/api/procure";
export default {
  name: "ProcureReturnDetail",
  data() {
    return {
      tableData: [],
      returnsNumber: "",
      returnMoney: "",
      warehouseName: "",
      remark: "",
      totalNum: null,
      totalPrice: null,
      id: "",
      isDetail: null,
      returnsState: "0",
    };
  },
  created() {
    this.id = this.$route.query.id ? this.$route.query.id : "";
    this.isDetail = this.$route.query.isDetail;
    if (this.id) {
      this.getExamineDetail();
    }
  },
  methods: {
    returnList() {
      this.closeTag();
    },
    async getExamineDetail() {
      const res = await reqExamineById({ id: this.id });
      if (res.code === 200) {
        this.tableData = res.data.storeReturnsVoList.map((item) => {
          if (!item.type) {
            item.type = "1";
          }
          return { ...item };
        });
        this.warehouseName = res.data.warehouseName;
        this.returnsNumber = res.data.returnsNumber;
        this.returnMoney = res.data.returnMoney;
        this.returnsState = res.data.returnsState;
        console.log("this.returnState", this.returnsState);
        this.remark = res.data.remark;
      }
    },
    async toExamine(state) {
      console.log("state", state);
      // return
      // if (state == 2) {
      const storeReturnsVoList = this.tableData.map((item) => {
        return {
          id: item.id,
          type: item.type,
          returnNum: item.returnNum,
          commodityId: item.commodityId,
          inboundDetailsId: item.inboundDetailsId,
          storeId: item.storeId,
        };
      });
      const res = await reqToExamine({
        id: this.id,
        returnsState: state,
        storeReturnsVoList: storeReturnsVoList
      });
      if (res.code === 200) {
        this.$message.success("审核成功");
        this.returnList();
      } else {
        // this.$message.error(res.message);
      }
      // } else {
      //   const res = await reqToExamine({ id: this.id, returnsState: state });
      //   if (res.code === 200) {
      //     this.$message.success("审核成功");
      //     this.returnList();
      //   } else {
      //     // this.$message.error(res.message);
      //   }
      // }
    },
  },
};
</script>

<style scoped lang="scss">
.flexContent {
  .top {
    h3 {
      margin: 0;
      margin-bottom: 10px;
    }

    .rows {
      display: flex;
      margin-bottom: 20px;

      .col {
        width: 33%;
      }
    }

    .one-line {
      .col {
        width: 100% !important;
      }
    }
  }
}
</style>
